#include "StdAfx.h"
#include "PhysicalObject.h"
#include "PhysicsGeometry.h"



PhysicalObject::PhysicalObject(PhysicsGeometry* geometry, float fMass)
{
	hkpRigidBodyCinfo rigidBodyInfo;
	rigidBodyInfo.m_mass = fMass;
	rigidBodyInfo.m_restitution = 0;

	hkpMassProperties massProperties;
	hkVector4 boxSize ( 1.0f, 2.0f, 3.0f );
	hkpInertiaTensorComputer::computeBoxVolumeMassProperties(boxSize, fMass, massProperties);

	rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor;

	rigidBodyInfo.m_shape = geometry->GetBoundingVolume();
	rigidBodyInfo.m_allowedPenetrationDepth = 0.02;

	m_pRigidBody = new hkpRigidBody(rigidBodyInfo);	
}


PhysicalObject::~PhysicalObject(void)
{
	m_pRigidBody->removeReference();
}

void PhysicalObject::SetPosition(const Vector4& vPos)
{
	m_pRigidBody->setPosition(hkVector4(vPos.GetX(), vPos.GetY(), vPos.GetZ(), vPos.GetW()));
}

void PhysicalObject::ApplyForce(float fDeltaTime, const Vector4& vForce)
{
	m_pRigidBody->applyForce(fDeltaTime, hkVector4(vForce.GetX(), vForce.GetY(), vForce.GetZ(), vForce.GetW()));
}

void PhysicalObject::SetVelocity(const Vector4& vVel)
{
	m_pRigidBody->setLinearVelocity(hkVector4(vVel.GetX(), vVel.GetY(), vVel.GetZ(), vVel.GetW()));
}